﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary;
namespace TheBestPlayer2016
{
    public class Client : IClientContract
    {
        public void UpdateMatchs(List<Match> matchs)
        {
            App.Matchs = matchs;

            //refresh grid
            if(App.MainWindowEl != null)
            {
                App.MainWindowEl.dataGrid.ItemsSource = App.Matchs;
                //App.MainWindowEl.dataGrid.
            }

            if (App.ChoosePlayerEl != null && App.ChoosePlayerEl.SelectedMatch != null)
            {
                Match match = App.Matchs.First(x => x.MatchDate == App.ChoosePlayerEl.SelectedMatch.MatchDate && x.TeamAway.Name == App.ChoosePlayerEl.SelectedMatch.TeamAway.Name && x.TeamHome.Name == App.ChoosePlayerEl.SelectedMatch.TeamHome.Name);
                App.ChoosePlayerEl.SelectedMatch = match; 
                App.ChoosePlayerEl.UpdatePlayers();
            }
        }
    }
}
